package com.ikunikun.mapper;

import com.ikunikun.dto.GoodsSalesDTO;
import com.ikunikun.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
	void insert(Orders orders);

	/**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from sky_take_out.orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

	/**
	 * 据订单转态和下单时间查询订单
	 * @param status
	 * @param orderTime
	 * @return
	 */
	@Select("select * from sky_take_out.orders where status = #{status} and order_time < #{orderTime}")
	List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

	/**
	 * 根据id查询订单
	 * @param id
	 * @return
	 */
	@Select("select * from sky_take_out.orders where id = #{id}")
	Orders getById(Long id);

	/**
	 * 查询指定日期的营业额
	 * @param map
	 * @return
	 */
	Double sumByMap(Map<String, Object> map);

	Integer countByMap(Map<String, Object> map);

	/**
	 * 统计指定时间区间内的销量排名前10
	 * @param begin
	 * @param end
	 * @return
	 */
	List<GoodsSalesDTO> getSalesTop(LocalDateTime begin, LocalDateTime end);
}
